//
//  SRAlbumService.m
//  StoryShow
//
//  Created by CyonLeuMBP on 2017/3/31.
//  Copyright © 2017年 qudiandu.cn. All rights reserved.
//

#import "SRAlbumService.h"
#import "SRGradeItemModel.h"
#import "FZHomeCourseModel.h"
#import "SRBookCatalogueModel.h"

@implementation SRAlbumService

/*
 * 获取年级列表
 */
+ (void)queryGradeListSuccessBlock:(FZSuccessBlock)successBlock failBlock:(FZFailureBlock)failureBlock {
    NSString *urlString = [[SRAPICreater sharedInstance] APIWithName:@"book_gradeList"];
    SRNetWorkManager *manager = [SRNetWorkManager sharedInstance];
    
    [manager GET:urlString needCache:YES parameters:nil responseClass:[SRGradeItemModel class] success:successBlock failure:failureBlock];
}

/*
 *  根据年级id获取教材
 */
+ (void)queryBooksWithGradeID:(NSString *)gradeID start:(NSInteger)start successBlock:(FZSuccessBlock)successBlock failBlock:(FZFailureBlock)failureBlock {
    NSString *urlString = [[SRAPICreater sharedInstance] APIWithName:@"book_bookList"];
    SRNetWorkManager *manager = [SRNetWorkManager sharedInstance];
    
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    [params setValue:@(start) forKey:@"start"];
    [params setValue:@(10) forKey:@"rows"];
    [params setValue:gradeID forKey:@"grade_id"];
    
    [manager GET:urlString needCache:NO parameters:params responseClass:[FZHomeCourseModel class] success:successBlock failure:failureBlock];
}

/*
 *  上报用户添加的书籍书本id,多个逗号隔开
 */
+ (void)addBooksWithBookIDs:(NSString *)bookIDs successBlock:(FZSuccessBlock)successBlock failBlock:(FZFailureBlock)failureBlock {
    NSString *urlString = [[SRAPICreater sharedInstance] APIWithName:@"book_download"];
    SRNetWorkManager *manager = [SRNetWorkManager sharedInstance];
    
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    [params setValue:bookIDs forKey:@"book"];
    
    [manager GET:urlString needCache:NO parameters:params responseClass:[FZHomeCourseModel class] success:successBlock failure:failureBlock];
}
/*
 *  上报用户录音
 */
+ (void)addUserAudioRecordWithTrackID:(NSString *)trackID
                               bookID:(NSString *)bookID
                               pageID:(NSString *)pageID
                                score:(NSInteger)score
                        audioFileName:(NSString *)fileName
                         successBlock:(FZSuccessBlock)successBlock
                            failBlock:(FZFailureBlock)failureBlock {
    
    NSString *urlString = [[SRAPICreater sharedInstance] APIWithName:@"show_trackAdd"];
    SRNetWorkManager *manager = [SRNetWorkManager sharedInstance];
    
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    [params setValue:trackID forKey:@"track_id"];
    [params setValue:bookID forKey:@"book_id"];
    [params setValue:pageID forKey:@"page_id"];
    
    [params setValue:@(score) forKey:@"score"];
    [params setValue:fileName forKey:@"audio"];

    
    [manager POST:urlString needCache:NO parameters:params responseClass:nil success:successBlock failure:failureBlock];
}

/*
 *  上报用户录音单元作品
 */
+ (void)addUserAudioWorkWithCatalogueID:(NSString *)catalogueID
                                 bookID:(NSString *)bookID
                                  score:(NSInteger)score
                          audioFileName:(NSString *)fileName
                             audioTrack:(NSString *)trackTimes
                               group_id:(NSString *)group_id
                                task_id:(NSString *)task_id
                           successBlock:(FZSuccessBlock)successBlock
                              failBlock:(FZFailureBlock)failureBlock {
    
    NSString *urlString = [[SRAPICreater sharedInstance] APIWithName:@"show_catalogueAdd"];
    SRNetWorkManager *manager = [SRNetWorkManager sharedInstance];
    
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    [params setValue:catalogueID forKey:@"catalogue_id"];
    [params setValue:bookID forKey:@"book_id"];
    [params setValue:trackTimes forKey:@"audio_track"];
    
    [params setValue:@(score) forKey:@"score"];
    [params setValue:fileName forKey:@"audio"];
    [params setValue:group_id forKey:@"group_id"];
    [params setValue:task_id forKey:@"task_id"];
    
    
    [manager POST:urlString needCache:NO parameters:params responseClass:nil success:successBlock failure:failureBlock];
}

/*
 *  根据教材id获取单元列表
 */
+ (void)queryCatalogueWithBookID:(NSString *)bookID start:(NSInteger)start successBlock:(FZSuccessBlock)successBlock failBlock:(FZFailureBlock)failureBlock {
    NSString *urlString = [[SRAPICreater sharedInstance] APIWithName:@"book_catalogue"];
    SRNetWorkManager *manager = [SRNetWorkManager sharedInstance];
    
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    [params setValue:@(start) forKey:@"start"];
    [params setValue:@(20) forKey:@"rows"];
    [params setValue:bookID forKey:@"book_id"];
    
    [manager GET:urlString needCache:NO parameters:params responseClass:[SRBookCatalogueModel class] success:successBlock failure:failureBlock];
}

@end
